<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 柯里化函数 -->

    <script>
        //普通的add函数
        function add(x,y){
            return x+y
        }
        //currying后
        function curryingAdd(x){
            return function(y){
                return x+y
            }
        }
        // console.log(add(1,2))
        // console.log(curryingAdd(1)(2))
        // console.log(curryingAdd(1))//返回函数
        //console.log(curryingAdd(1)(2)(3))//会报错
        //面试题
        /*
          // 实现一个add方法，使计算结果能够满足如下预期：
            add(1)(2)(3) = 6;
            add(1, 2, 3)(4) = 10;
            add(1)(2)(3)(4)(5) = 15;  
        */
        function addMore(){
            console.log('1111111',arguments)
            var _args = Array.prototype.slice.call(arguments)
             console.log('ddd',_args)
            var _adder = function() {
                console.log('2222222',...arguments)
                _args.push(...arguments);
                console.log('ccc',_args)
                return _adder
            }
            console.log(_adder)
            _adder.toString = function() {
                return _args.reduce(function(a,b){
                    return a+b
                })
            }
            return _adder
        }
        console.log("#########")
        addMore(1)(2)(3)
        console.log(addMore(1)(2)(3))
        //console.log(addMore(1, 2, 3)(4)(5))// 6
        // console.log('ddd',addMore(1, 2, 3)(4))              // 10
        // let hh = addMore(1)(2)(3)(4)(5)          // 15
        // console.log("DD",hh(6))
        // addMore(2, 6)(1)                // 9
    </script>
</body>
</html>